/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.services.customer;

/**
 *
 * @author jay
 */

import java.util.HashMap;
import src.domain.customer.District;
import java.util.List;
import java.util.Map;
import javax.faces.model.SelectItem;
import src.services.CRUEDService;

public class DistrictModel implements java.io.Serializable {
    
    private CRUEDService service;
    
    public DistrictModel() {
        service = new CRUEDService();
    }
    
    public List<District> findAll(Map<String, String> filters) {
        return (List<District>) service.findAll("District", filters);
    }
    public List<SelectItem> listAll() {
        return service.listAll("District", "districtId", "districtName");
    }

    public List<SelectItem> listAll(Map<String, String> filters) {
        //ini utk kebutuhan combo change aja
         //return service.listAll("src.domain.customer.District as tb inner join tb.province as tc", "districtId", "districtName",filters);
         return service.listAll("District as tb", "districtId", "districtName",filters);
    }
    
    public boolean saveData(District data) {
        return service.saveData(data);
    }
    
    public boolean deleteData(District data) {
        return service.deleteData(data);
    }
    
    public District getById(Integer id) {
        
        
        if (id != null) {   
            Map<String, String> where = new HashMap<>();
            where.put("districtId", id.toString());
            if (id > 0) 
                return (District) service.getObjectSQL("from District", where);
            else return null;
            
        } 
        else 
            return null;
    }
}
